package com.project.rfidpage.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.project.rfidpage.dto.BgGjxlDto;
import com.project.rfidpage.dto.BgGjxlParam;
import com.project.rfidpage.entity.BgGjxl;
import com.project.rfidpage.mapper.BgGjxlMapper;
import com.project.rfidpage.service.BgGjxlService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BgGjxlServiceImpl implements BgGjxlService {

    @Resource
    private BgGjxlMapper bgGjxlMapper;

    @Override
    @DS("master")
    public List<BgGjxlDto> getListForPage(BgGjxlParam param) {
        return bgGjxlMapper.selectListByUid(param);
    }

    @Override
    @DS("master")
    public List<BgGjxl> getByRepeat(String bgno, Integer jgxlid, String zdlx, String xh) {
        Example example = new Example(BgGjxl.class);
        Example.Criteria c = example.createCriteria();
        c.andEqualTo("bgno", bgno);
        c.andEqualTo("jgxlid", jgxlid);
        c.andEqualTo("zdlx", zdlx);
        c.andEqualTo("xh", xh);
        return bgGjxlMapper.selectByExample(example);
    }

    @Override
    @DS("master")
    public Integer getJgzdid(BgGjxl param) {
        return bgGjxlMapper.selectJgzdid(param);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("master")
    public void insert(BgGjxl entity) {
        bgGjxlMapper.insert(entity);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("master")
    public void delete(BgGjxl entity) {
        Example example = new Example(BgGjxl.class);
        Example.Criteria c = example.createCriteria();
        c.andEqualTo("bgno", entity.getBgno());
        c.andEqualTo("jgxlid", entity.getJgxlid());
        c.andEqualTo("zdlx", entity.getZdlx());
        c.andEqualTo("xh", entity.getXh());
        bgGjxlMapper.deleteByExample(example);
    }
}
